#pragma once
#ifndef _CR_HTTP_ERROR_H_
#define _CR_HTTP_ERROR_H_

NS_CR_BEGIN

namespace http
{
	enum class ErrorCode 
	{
		OK = 0,
		CONNECTION_FAILURE,
		EMPTY_RESPONSE,
		HOST_RESOLUTION_FAILURE,
		INTERNAL_ERROR,
		INVALID_URL_FORMAT,
		NETWORK_RECEIVE_ERROR,
		NETWORK_SEND_FAILURE,
		OPERATION_TIMEDOUT,
		PROXY_RESOLUTION_FAILURE,
		SSL_CONNECT_ERROR,
		SSL_LOCAL_CERTIFICATE_ERROR,
		SSL_REMOTE_CERTIFICATE_ERROR,
		SSL_CACERT_ERROR,
		GENERIC_SSL_ERROR,
		UNSUPPORTED_PROTOCOL,
		UNKNOWN_ERROR = 1000,
	};

	class Error 
	{
	public:
		Error() 
			: code{ ErrorCode::OK } 
		{}

		template <typename TextType>
		Error(const int32_t& curl_code, TextType&& p_error_message)
			: code{ getErrorCodeForCurlError(curl_code) }
			, message{ _STD_FWD(p_error_message) }
		{}

		explicit operator bool() const 
		{
			return code != ErrorCode::OK;
		}

		ErrorCode code;
		string message;

	private:
		static ErrorCode getErrorCodeForCurlError(int32_t curl_code);
	};
}

NS_CR_END

#endif // !_CR_HTTP_ERROR_H_
